<?php
namespace Home\Controller;
use Think\Controller;
class ZfbController extends Controller {
    public function index()
    {
    	$this->display('index');
    }

    public function pay()
    {
  // 	require_once dirname(dirname(__FILE__)).'/config.php';
		// require_once dirname(__FILE__).'/service/AlipayTradeService.php';
		// require_once dirname(__FILE__).'/buildermodel/AlipayTradePagePayContentBuilder.php';
		vendor("Ali.pagepay.buildermodel.AlipayTradePagePayContentBuilder");
		vendor("Ali.pagepay.service.AlipayTradeService");

	    //商户订单号，商户网站订单系统中唯一订单号，必填
	    $out_trade_no = trim($_POST['WIDout_trade_no']);

	    //订单名称，必填
	    $subject = trim($_POST['WIDsubject']);

	    //付款金额，必填
	    $total_amount = trim($_POST['WIDtotal_amount']);

	    //商品描述，可空
	    $body = trim($_POST['WIDbody']);

		//构造参数
		$payRequestBuilder = new \AlipayTradePagePayContentBuilder();
		$payRequestBuilder->setBody($body);
		$payRequestBuilder->setSubject($subject);
		$payRequestBuilder->setTotalAmount($total_amount);
		$payRequestBuilder->setOutTradeNo($out_trade_no);

		$aop = new \AlipayTradeService($config);

		/**
		 * pagePay 电脑网站支付请求
		 * @param $builder 业务参数，使用buildmodel中的对象生成。
		 * @param $return_url 同步跳转地址，公网可以访问
		 * @param $notify_url 异步通知地址，公网可以访问
		 * @return $response 支付宝返回的信息
	 	*/
		$response = $aop->pagePay($payRequestBuilder,$config['return_url'],$config['notify_url']);

		//输出表单
		var_dump($response);


		$config = array (	
		//应用ID,您的APPID。

		'app_id' =>"2016082600316022",

		//商户私钥
		'merchant_private_key' =>"MIIEogIBAAKCAQEAm6nOd/enl6Jdr6DE9b+muy6zaTcoDhfksZhg9L2kfGNwlwj+N4fM4C5Q6q9m4Y7cPdnItoQiFnbVSKMhuDb+CL2Sy3wev38VM1pC23sJN86dQ6gqKXaA9CCKYt7uRz0ygSZ1g89LaCpZu+Oig6+mbPh2UKLkMGMUOcQ62QY5Qa1ITl/SeTlhB5M9UMdkd5lU+Fr1PqsAMEseN1r8liV5TDGPi6HpCvT9PKC9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5u3a+g2w3zGz9xt2zS442SeuTNF5vdqjIR4/wi1KYXE237ObCwh+mHR75giWVbv8GHsYNqBSD3LAfwFtzoFij6N3lpUz0im4Udl31AoGADo9dlCstNx9wQ+lg4Db/JU5I6ZqkfFm/PY6J4GbgmD5nRx/aU+GfS2ewftrFUd67U+H9a0/jn3GdEetMCioevWynRuAAnqZNpVgf+BRTI2qIPNEfPDQ03QjXxk/cG8lbUoucsJiiAKdO9yMYy3O1NAL6EMcOkko/X2NBUDZsh+w=",

		//异步通知地址
		'notify_url' => "http://www.exercise.com/alipay.trade.page.pay-PHP-UTF-8/notify_url.php",
		
		//同步跳转
		'return_url' => "http://www.exercise.com/alipay.trade.page.pay-PHP-UTF-8/return_url.php",

		//编码格式
		'charset' => "UTF-8",

		//签名方式
		'sign_type'=> "RSA2",

		//支付宝网关
		'gatewayUrl' => "https://openapi.alipaydev.com/gateway.do",

		//支付宝公钥,查看地址：https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
		'alipay_public_key' => "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAm6nOd/enl6Jdr6DE9b+muy6zaTcoDhfksZhg9L2kfGNwlwj+N4fM4C5Q6q9m4Y7cPdnItoQiFnbVSKMhuDb+CL2Sy3wev38VM1pC23sJN86dQ6gqKXaA9CCKYt7uRz0ygSZ1g89LaCpZu+Oig6+mbPh2UKLkMGMUOcQ62QY5Qa1ITl/SeTlhB5M9UMdkd5lU+Fr1PqsAMEseN1r8liV5TDGPi6HpCvT9PKC9sWAKJKAPGSiYViWAyoziPDbl8Kc/uhHPEgbtwqD6zWE8blBC2Uyb/2j3f6xmh/9ViCIqHn+men8W0FIA/8Yb4Rj5OsVDyVxbolLn/Jn7xS6eoxEnKwIDAQAB",
		);
    }
}